<?php

namespace App\Http\Controllers;

use App\Http\Resources\Personal\InfoResource;
use App\Http\Resources\Personal\MenuResource;
use App\Models\System\Admin;
use App\Models\System\Menu;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PersonalController extends Controller
{
    /** 获取用户信息 */
    public function info(Request $request): JsonResponse
    {
        /** @var Admin $user */
        $user = $request->user();

        return $this->success(new InfoResource($user));
    }

    /**
     * 获取用户拥有的code
     */
    public function codes(Request $request): JsonResponse
    {
        /** @var Admin $user */
        $user = $request->user();
        $codes = $user->getMenusCodes();

        return $this->success([
            'codes' => $codes,
        ]);
    }

    /**
     * 获取当前用户的菜单
     */
    public function menus(Request $request): JsonResponse
    {
        /** @var Admin $user */
        $user = $request->user();

        return $this->success(MenuResource::collection((Menu::getMenusByAdmin($user))));
    }
}
